package practice1F;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;

import javax.xml.bind.JAXBException;

import org.jdom.Comment;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.ProcessingInstruction;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

/**
 * @author $Author:$
 * @version $Id: $
 */
public class Main {
	public static void main(String[] args) throws JAXBException, IOException {
		
		Document doc = new Document();
		HashMap<String, String> proc_attrs = new HashMap<String,String>();
		proc_attrs.put("type", "text/xsl");
		proc_attrs.put("href", "test.xsl");
		doc.addContent(new ProcessingInstruction("xml-stylesheet", proc_attrs));
		doc.addContent(new Comment(" Generated automatically. Don't change it. "));
		Element clazz = new Element("class");
		doc.addContent(clazz);
		
		clazz
			.setNamespace(Namespace.getNamespace("h","http://www.dei.uc.pt/EAI"))
			.addContent(new Element("student")
				.setNamespace(Namespace.getNamespace("h","http://www.dei.uc.pt/EAI"))
				.addContent(new Element("name").setText("Alberto Caeiro"))
				.addContent(new Element("age").setText("21"))
				.setAttribute("id", "201134441110"))
			.addContent(new Element("student")
				.setNamespace(Namespace.getNamespace("h","http://www.dei.uc.pt/EAI"))
				.addContent(new Element("name").setText("Patricia"))
				.addContent(new Element("age").setText("22"))
				.setAttribute("id", "201134441116"))
			.addContent(new Element("student")
				.setNamespace(Namespace.getNamespace("h","http://www.dei.uc.pt/EAI"))
				.addContent(new Element("name").setText("Luis"))
				.addContent(new Element("age").setText("21"))
				.setAttribute("id", "201134441210"));
		
	
		XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
		out.output(doc, System.out);
		out.output(doc, new FileOutputStream("gen/practice1F.xml"));
	}
}
